package com.bawei.a2010douyin.ui.shopping;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.bawei.a2010douyin.R;
import com.bawei.a2010douyin.base.mvp.BaseFragment;
import com.bawei.a2010douyin.base.mvp.BaseMvpFragment;
import com.bawei.a2010douyin.entity.GoodsEntity;

import java.util.List;

public class ShoppingFragment extends BaseMvpFragment<ShoppingContract.IShoppingView,ShoppingPresenter> implements ShoppingContract.IShoppingView {
    private RecyclerView rv;
    private ShoppingAdapter mShoppingAdapter;




    @Override
    public int bindLayout() {
        return R.layout.fragment_shopping;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        rv = (RecyclerView) findViewById(R.id.rv);
        mShoppingAdapter = new ShoppingAdapter(R.layout.item_goods);
        rv.setAdapter(mShoppingAdapter);
        rv.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));

    }

    @Override
    public ShoppingPresenter createPresenter() {
        return new ShoppingPresenter();
    }

    @Override
    public void initData() {
        mPresenter.goods(0,1,10);
    }

    @Override
    public void showGoods(List<GoodsEntity> data) {
       mShoppingAdapter.getData().addAll(data);
       mShoppingAdapter.notifyDataSetChanged();
    }
}